package com.cmcc.linlaker.ui.query;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.bean.ImageUploadBean;
import com.cmcc.linlaker.ui.query.adapter.CustomPagerAdapter;
import com.cmcc.linlaker.ui.query.adapter.CustomPagerAdapter2;
import com.cmcc.linlaker.utils.BarUtils;

import java.util.ArrayList;

public class ImageScanActivity extends AppCompatActivity {
    private ArrayList<String> imageList;
    private ArrayList<ImageUploadBean> imageBeanList;
    private int position;

    @Nullable
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_scan);

        BarUtils.initStatusBar(this);

        initView();
    }

    private ViewPager image_viewpager;

    private void initView() {
        position = getIntent().getIntExtra("position", 0);

        imageList = (ArrayList<String>) getIntent().getSerializableExtra("imageList");
        imageBeanList = (ArrayList<ImageUploadBean>) getIntent().getSerializableExtra("imageBeanList");

        image_viewpager = findViewById(R.id.image_viewpager);
        setImageData();
    }

    /**
     * 处理图片数据
     */
    private void setImageData() {
        if (imageList != null && imageList.size() > 0) {
            CustomPagerAdapter adapter = new CustomPagerAdapter(ImageScanActivity.this, imageList);
            image_viewpager.setAdapter(adapter);
            image_viewpager.setCurrentItem(position);
        } else {
            CustomPagerAdapter2 adapter = new CustomPagerAdapter2(ImageScanActivity.this, imageBeanList);
            image_viewpager.setAdapter(adapter);
            image_viewpager.setCurrentItem(position);
        }
    }


    public void back(View view) {
        finish();
    }
}
